package dt.inlee.domain;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;

/**
 * The persistent class for the SYSUSER database table.
 * 
 */
@Entity
@Table(name = "KQ_OPERATOR")
public class SysUser implements Serializable {
	private static final long serialVersionUID = -2830652976117676035L;
	public static final String COL_LoginID = "OpLogID";
	public static final String COL_EnterpriseID = "CompanyID";
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "OpID")
	private int id;
	// 企业id,用户名,密码,表id
	private Integer isvalidsm;
	private Integer logincount;
	@Column(length = 4000)
	private String remark;
	// 生效开始日期
	private Date effectStartDate;
	// 生效结束日期
	private Date effectEndDate;
	// 传真
	private String fax;
	// 真实姓名
	@Column(nullable = true, name = "OpName")
	private String realName;
	// 地址
	@Column(name = "Addr")
	private String address;
	// email
	@Column(name = "Email")
	private String email;
	// 身份证号
	private String identityCard;
	// 性别:
	private String gender;
	// 手机
	private String mobile;
	// 是否是操作员
	private Boolean isOperator;
	// 用户名
	@Column(name = "OpLogID")
	private String userName;
	// 用户密码
	@Column(name = "OpPass")
	private String password;
	// 状态(true:启用；false:禁止)
	private Boolean disabled;
	@ManyToMany(fetch = FetchType.LAZY, cascade = { CascadeType.MERGE,
			CascadeType.PERSIST, CascadeType.REFRESH })
	private List<SysOrganization> sysOrganizations = new ArrayList<SysOrganization>();
	@ManyToMany(mappedBy = "sysUsers", fetch = FetchType.LAZY, cascade = {
			CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH })
	private List<SysRole> sysRoles = new ArrayList<SysRole>();
	// 物业id
	private int wyId;

	private Date updatetime;
	private Date createtime;

	public int getWyId() {
		return wyId;
	}

	public void setWyId(int wyId) {
		this.wyId = wyId;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public Date getEffectStartDate() {
		return effectStartDate;
	}

	public void setEffectStartDate(Date effectStartDate) {
		this.effectStartDate = effectStartDate;
	}

	public Date getEffectEndDate() {
		return effectEndDate;
	}

	public void setEffectEndDate(Date effectEndDate) {
		this.effectEndDate = effectEndDate;
	}

	public Integer getIsvalidsm() {
		return isvalidsm;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public static long getSerialVersionUID() {
		return serialVersionUID;
	}

	public Integer isIsvalidsm() {
		return isvalidsm;
	}

	public void setIsvalidsm(Integer isvalidsm) {
		this.isvalidsm = isvalidsm;
	}

	public Integer getLogincount() {
		return logincount;
	}

	public void setLogincount(Integer logincount) {
		this.logincount = logincount;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	public String getFax() {
		return fax;
	}

	public void setFax(String fax) {
		this.fax = fax;
	}

	public String getRealName() {
		return realName;
	}

	public void setRealName(String realName) {
		this.realName = realName;
	}

	public String getIdentityCard() {
		return identityCard;
	}

	public void setIdentityCard(String identityCard) {
		this.identityCard = identityCard;
	}

	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	public Boolean getIsOperator() {
		return isOperator;
	}

	public void setIsOperator(Boolean isOperator) {
		this.isOperator = isOperator;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public Boolean getDisabled() {
		return disabled;
	}

	public void setDisabled(Boolean disabled) {
		this.disabled = disabled;
	}

	public String getGender() {
		return gender;
	}

	public void setGender(String gender) {
		this.gender = gender;
	}

	public List<SysOrganization> getSysOrganizations() {
		return sysOrganizations;
	}

	public void setSysOrganizations(List<SysOrganization> sysOrganizations) {
		this.sysOrganizations = sysOrganizations;
	}

	public List<SysRole> getSysRoles() {
		return sysRoles;
	}

	public void setSysRoles(List<SysRole> sysRoles) {
		this.sysRoles = sysRoles;
	}

	public String toString() {
		return new ToStringBuilder(this).append("id", getId()).toString();
	}

	public boolean equals(Object other) {
		if (!(other instanceof SysUser))
			return false;
		SysUser castOther = (SysUser) other;
		return new EqualsBuilder().append(this.getId(), castOther.getId())
				.isEquals();
	}

	public int hashCode() {
		return new HashCodeBuilder().append(getId()).toHashCode();
	}

	public Date getUpdatetime() {
		return updatetime;
	}

	public void setUpdatetime(Date updatetime) {
		this.updatetime = updatetime;
	}

	public Date getCreatetime() {
		return createtime;
	}

	public void setCreatetime(Date createtime) {
		this.createtime = createtime;
	}

	public boolean isSysAdmin() {
		List<SysRole> roleList = this.getSysRoles();
		for (SysRole role : roleList) {
			if (role.getCode().equals("manage"))
				return true;
		}
		return false;
	}

	public boolean isKqAdmin() {
		List<SysRole> roleList = this.getSysRoles();
		for (SysRole role : roleList) {
			if (role.getCode().equals("kq"))
				return true;
		}
		return false;
	}
}